package com.template.enums;

/**
 * @description:
 * @author: yanchao
 * @time: 2021-12-29 18:31
 */
public enum FeatureMethod {

    PUT_FEATURE("putFeature", "根据id往extra_field字段写入数据", "<script> UPDATE %s SET extra_field = json_set(IFNULL(extra_field,'{}'),'$.${key}', #{value}) WHERE %s=#{%s} </script>"),
    PUT_FEATURES("putFeatures", "根据id往extra_field字段写入多个key value数据", "" +
            "<script> UPDATE " +
            "            %s " +
            "        SET " +
            "            extra_field = json_set(IFNULL(extra_field,'{}'), " +
            "                    <foreach item=\"value\" index=\"key\" collection=\"values.entrySet()\" separator=\",\"> " +
            "                        '$.${key}', #{value} " +
            "                    </foreach> " +
            "                ) " +
            "        WHERE " +
            "            %s = #{%s}; </script>"),

    GET_FEATURE("getFeature", "根据id和key从extra_field字段查询数据", "<script> SELECT JSON_EXTRACT(extra_field, '$.${key}') FROM %s WHERE %s=#{%s} </script>"),
    GET_FEATURES("getFeatures", "根据id和keys从extra_field字段查询数据", "<script> SELECT " +
            " <foreach item=\"value\" index=\"key\" collection=\"keys\" separator=\",\"> " +
            "    JSON_EXTRACT(extra_field, '$.${value}') as ${value} " +
            " </foreach>" +
            " FROM %s WHERE %s=#{%s} </script>");

    private final String method;

    private final String desc;

    private final String sql;
    FeatureMethod(String method, String desc, String sql) {

        this.method = method;

        this.desc = desc;

        this.sql = sql;

    }
    public String getMethod() {
        return method;
    }
    public String getDesc() {
        return desc;
    }
    public String getSql() {
        return sql;
    }

}
